import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: user
 * Date: 2023-06-18
 * Time: 13:19
 */
public class MinStack {
    private Stack<Integer> stack = new Stack<>();
    private Stack<Integer> Minstack= new Stack<>();

    public void push(int val){
        stack.push(val);
        if (Minstack.empty()){
            Minstack.push(val);
        }else {
            if (val<= Minstack.peek()){
                Minstack.push(val);
            }
        }
    }

    public void pop(){
        if(stack.empty()){
            return;
        }else {
           int val=stack.pop();
            if(val== Minstack.peek()){
                Minstack.pop();
            }
        }
    }

    public int top(){
        if (stack.empty()){
            return -1;
        }else {
           return stack.peek();
        }
    }

    public int getMin(){
            return Minstack.peek();
    }


    public static void main(String[] args) {
        MinStack minStack1 = new MinStack();
        minStack1.push(-2);
        minStack1.push(0);
        minStack1.push(1);
        int x1 = minStack1.getMin();
        int x2 = minStack1.top();
        minStack1.pop();
        int x4 = minStack1.getMin();
        System.out.println(x1);
    }
}
